package com.uha.reggie.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author uha
 * @date 2023/6/15
 * @apiNote 通用返回结果，将服务端响应的数据封装为此对象
 * @param <T>
 */
@Data
public class ReggieResult<T> {

    /**
     * 约定code=1为成功 其他数字为失败
     */

    private Integer code;

    /**
     * 错误消息
     */

    private String msg;

    /**
     * 数据
     */

    private T data;

    //动态数据

    private Map map = new HashMap();

    /**
     * 成功
     * @param object
     * @param <T>
     * @return
     */
    public static <T> ReggieResult<T> success(T object){
        ReggieResult<T> reggieResult = new ReggieResult<T>();
        reggieResult.data = object;
        reggieResult.code = 1;
        return reggieResult;
    }

    public static <T> ReggieResult<T> error(String msg){
        ReggieResult<T> reggieResult = new ReggieResult<T>();
        reggieResult.msg = msg;
        reggieResult.code = 0;
        return reggieResult;
    }

    public ReggieResult<T> add(String key,Object value){
        this.map.put(key,value);
        return this;
    }



}
